using QueryBuilder.Core.Query.Type;

namespace QueryBuilder.Core.Query.Presenters.Mysql
{
    /// <summary>
    /// 
    /// </summary>
    public class IdentifierQuotedMysqlConstraintPresenter : MysqlConstraintPresenter
    {
        private const string Quote = "`";

        /// <summary>
        /// Initializes a new instance of the <see cref="IdentifierQuotedMysqlConstraintPresenter"/> class.
        /// </summary>
        /// <param name="typeMappingsRegistry">The type mappings registry.</param>
        public IdentifierQuotedMysqlConstraintPresenter(TypeMappingsRegistry typeMappingsRegistry) : base(typeMappingsRegistry)
        {
        }

        /// <summary>
        /// Presents the table.
        /// </summary>
        /// <param name="table">The table.</param>
        protected override void PresentTable(ITable table)
        {
            this.Result.Append(Quote);
            this.Result.Append(table.Name);
            this.Result.Append(Quote);
        }

        /// <summary>
        /// Presents the specified column.
        /// </summary>
        /// <param name="column">The column.</param>
        public override void Present(IColumn column)
        {
            this.Result.Append(Quote);
            this.Result.Append(column.Table.Name);
            this.Result.Append(Quote);
            this.Result.Append(SqlFragments.Point);
            this.Result.Append(column.Name);
        }

        /// <summary>
        /// Presents the specified aliased constraint.
        /// </summary>
        /// <param name="aliasedConstraint">The aliased constraint.</param>
        public override void Present(AliasedConstraint aliasedConstraint)
        {
            aliasedConstraint.Constraint.Accept(this);
            this.Result.Append(SqlFragments.Space);
            this.Result.Append("AS");
            this.Result.Append(SqlFragments.Space);
            this.Result.Append(Quote);
            this.Result.Append(aliasedConstraint.Alias);
            this.Result.Append(Quote);
        }
    }
}